/**
 * @Project : algorithm-learning
 * @Author : Ruoyu Wang
 * @User : Momenta
 * @DateTime : 2024/4/16 17:39
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    double findMaxAverage(vector<int> &nums, int k) {
        double sum = 0.0;
        for (int i = 0; i < k; ++i) {
            sum += nums[i];
        }
        double res = sum / k;
        for (int i = 0, j = k; j < nums.size(); ++i, ++j) {
            sum -= nums[i];
            sum += nums[j];
            res = max(res, sum / k);
        }
        return res;
    }
};